//
//  OldGoldManageViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15-6-9.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "OldGoldManageViewController.h"
#import "OldGoldManageTableViewCell.h"
#import "GuideListTableViewCell.h"
#import "OldGoldDetailTableViewCell.h"
#import "OldMeterialTableViewCell.h"
#import "EGORefreshTableHeaderView.h"
#import "OldGoldDetailViewController.h"
#import "OldGoldDetailSubmitViewController.h"
#import "FilterViewController.h"
#import "CancelOldViewController.h"
@interface OldGoldManageViewController ()<EGORefreshTableHeaderDelegate,OldGoldManageTableViewCellDelegate,OldGoldDetailSubmitDelegate,FilterViewControllerDelegate,OldGoldDetailDelegate,CancelOldDelegate>
{
    FilterViewController *filterVC;
    OldGoldDetailViewController *oldGoldDetailVC;
    OldGoldDetailSubmitViewController *submitVC;
    CancelOldViewController *cancelOldVC;
    EGORefreshTableHeaderView *_refreshHeaderView;
   // FilterViewController *filterVC;
    BOOL _reloading;

    NSUInteger _productPageIndex;
    NSUInteger _productTotalCount;
    NSUInteger _productTotalPage;
    
   // NSMutableArray *oldGoldQuatityArray;
    NSMutableArray *oldGoldNumArray;
    NSMutableArray *oldGoldGuideNameArray;
    NSMutableArray *oldGoldDateArray;
    NSMutableArray *oldGoldStatusArray;
    NSMutableArray *oldGoldWeightArray;
   // NSMutableArray *oldGoldReasonArray;
    NSMutableArray *oldNumberArray;
    NSMutableArray *cutNumberArray;
  
    NSString *docNumStr;
     NSString *whsCodeStr;
    NSString *guideCodeStr;
    
    NSInteger oldCellTag;
    
    UITextField *inputTextField;
    NSMutableArray *filterTypeCodeArray ;
    NSMutableArray *inputFilterCodeArray;
    NSMutableArray *inputMinResultFilterNameArray;
    NSMutableArray *inputMaxResultFilterNameArray;
    NSMutableArray *selectFilterCodeArray;
    NSMutableArray *selectFilterNameArray;
    NSMutableArray *selectCustomTimeArray ;
    NSMutableArray *customTimeFilterTypeCodeArray ;
    NSString *startTimeStr;
    NSString *endTimeStr;

   
}
- (void)reloadTableViewDataSource;
- (void)doneLoadingTableViewData;
@end

@implementation OldGoldManageViewController
-(void)viewWillAppear:(BOOL)animated
{
   
    if (oldGoldDetailVC.view!=nil) {
        
        [oldGoldDetailVC removeFromParentViewController];
        [oldGoldDetailVC.view removeFromSuperview];
        
    }
    if (cancelOldVC.view!=nil) {
        [cancelOldVC removeFromParentViewController];
        [cancelOldVC.view removeFromSuperview];
    }
    if (submitVC.view!=nil) {
        
        [submitVC removeFromParentViewController];
        [submitVC.view removeFromSuperview];
        
    }

    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    [self initOldGoldList];
    
    [self initUpperViewContainer];
    [self initOrderFilterView];
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];

}
-(void)initUpperViewContainer
{
    whsCodeStr=@"";
    guideCodeStr=@"";
    docNumStr=@"";
  }
-(void)initOrderFilterView
{
    inputFilterCodeArray=[NSMutableArray array];
    inputMinResultFilterNameArray=[NSMutableArray array];
    inputMaxResultFilterNameArray=[NSMutableArray array];
    filterTypeCodeArray=[NSMutableArray array];
    customTimeFilterTypeCodeArray=[NSMutableArray array];
    selectFilterCodeArray=[NSMutableArray array];
    selectFilterNameArray=[NSMutableArray array];
    selectCustomTimeArray=[NSMutableArray array];
    
    startTimeStr=@"";
    endTimeStr=@"";
    
    [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
    [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    // [_orderFilterViewContainer bringSubviewToFront:_resetFilterBtn];
    
    _orderFilterBtn.layer.borderColor=[[UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1] CGColor];
    _orderFilterBtn.layer.borderWidth= 1.0f;
    _orderFilterBtn.layer.cornerRadius=4;
    
    [_orderFilterBtn addTarget:self action:@selector(orderFilterBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
}

-(void)initOldGoldList
{
    _searchTextField.text=@"";
  //  oldGoldQuatityArray=[NSMutableArray array];
    oldGoldNumArray=[NSMutableArray array];
    oldGoldGuideNameArray=[NSMutableArray array];
    oldGoldDateArray=[NSMutableArray array];
    oldGoldStatusArray=[NSMutableArray array];
    oldGoldWeightArray=[NSMutableArray array];
   // oldGoldReasonArray=[NSMutableArray array];
    cutNumberArray=[NSMutableArray array];
    oldNumberArray=[NSMutableArray array];
}
-(void)orderFilterBtnClick
{
    if (filterVC.view!=nil) {
        
        [filterVC removeFromParentViewController];
        [filterVC.view removeFromSuperview];
        
    }
    filterVC=[[FilterViewController alloc] init];
    filterVC.delegate=self;
    filterVC.docTypeStr=@"OldMaterial";
    filterVC.selectCustomTimeArray=[NSMutableArray arrayWithArray:selectCustomTimeArray];
    filterVC.startTimeStr=startTimeStr;
    filterVC.endTimeStr=endTimeStr;
    // NSLog(@"selectFilterNameArray=22222======%@",selectFilterNameArray);
    filterVC.selectFilterNameArray=[NSMutableArray arrayWithArray:selectFilterNameArray];
    filterVC.view.frame = CGRectMake(0,
                                     0,
                                     self.view.bounds.size.width,
                                     self.view.bounds.size.height);
    
    [self addChildViewController:filterVC];
    [self.view addSubview:filterVC.view];
}
-(void)confirmFilterBtnClick:(NSMutableArray *)commonFilterTypeCodeArray commonSelectFilterCodeArray:(NSMutableArray *)commonSelectFilterCodeArray commonInputFilterCodeArray:(NSMutableArray *)commonInputFilterCodeArray commonInputMinResultFilterNameArray:(NSMutableArray *)commonInputMinResultFilterNameArray commonInputMaxResultFilterNameArray:(NSMutableArray *)commonInputMaxResultFilterNameArray commonCustomTimeFilterTypeCodeArray:(NSMutableArray *)commonCustomTimeFilterTypeCodeArray commonSelectCustomTimeArray:(NSMutableArray *)commonSelectCustomTimeArray commonSelectFilterNameArray:(NSMutableArray *)commonSelectFilterNameArray  commonStartTimeStr:(NSString *)commonStartTimeStr commonEndTimeStr:(NSString *)commonEndTimeStr isDefault:(NSString *)isDefault
{
    
    if ([isDefault isEqualToString:@"Y"]) {
        //  NSLog(@"_isDefault0000===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:80.0f/255.0f green:80.0f/255.0f blue:80.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"shaixuandingdan_.png"]];
    }
    else{
        // NSLog(@"_isDefault1111===%@",isDefault);
        [_orderFilterTitleLabel setTextColor:[UIColor colorWithRed:203.0f/255.0f green:164.0f/255.0f blue:67.0f/255.0f alpha:1.0f]];
        [_orderFilterImage setImage:[UIImage imageNamed:@"yishaixuan_.png"]];
    }
    
    filterTypeCodeArray=commonFilterTypeCodeArray;
    selectFilterCodeArray=commonSelectFilterCodeArray;
    inputFilterCodeArray=commonInputFilterCodeArray;
    inputMinResultFilterNameArray=commonInputMinResultFilterNameArray;
    inputMaxResultFilterNameArray=commonInputMaxResultFilterNameArray;
    customTimeFilterTypeCodeArray=commonCustomTimeFilterTypeCodeArray;
    selectCustomTimeArray=commonSelectCustomTimeArray;
    selectFilterNameArray=commonSelectFilterNameArray;
    
    startTimeStr=commonStartTimeStr;
    endTimeStr=commonEndTimeStr;
    
    [oldGoldNumArray removeAllObjects];
    //[oldGoldQuatityArray removeAllObjects];
    [oldGoldGuideNameArray removeAllObjects];
    [oldGoldDateArray removeAllObjects];
    [oldGoldStatusArray removeAllObjects];
    [oldGoldWeightArray removeAllObjects];
    // [oldGoldReasonArray removeAllObjects];
    [cutNumberArray removeAllObjects];
    [oldNumberArray removeAllObjects];
    
    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
}

-(void) loadProductNextPage:(NSUInteger)oldPageNum {
    if(oldPageNum!=0 && _productTotalCount<=oldGoldNumArray.count)
        return;
    if(oldPageNum == 0){
        [oldGoldNumArray removeAllObjects];
        [_oldGoldManageListTableView reloadData];
    }
    _productPageIndex=oldPageNum+1;
    [self requestDisplayList: _productPageIndex pageSize:6];
}
-(void)requestDisplayList:(NSUInteger)pageIndex pageSize:(NSUInteger)pageSize
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        NSNumber *pageSizeNumber = [NSNumber numberWithInteger:pageSize];
        NSNumber *pageIndexNumber = [NSNumber numberWithInteger:pageIndex];
        [params setObject:pageSizeNumber forKey:@"PageSize"];
        [params setObject:pageIndexNumber forKey:@"PageIndex"];
        [params setObject:_searchTextField.text forKey:@"KeyWord"];
        NSMutableArray *mDocumentLine=[NSMutableArray array];
        for (int i=0; i<filterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:[filterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            [dic setValue:[selectFilterCodeArray objectAtIndex:i] forKey:@"FilterCode"];
            [mDocumentLine addObject:dic];
            
        }
        NSMutableArray *mDocumentLine1=[NSMutableArray array];
        for (int i=0; i<customTimeFilterTypeCodeArray.count; i++) {
            
            NSMutableDictionary *dic = [NSMutableDictionary dictionary];
            [dic setValue:[customTimeFilterTypeCodeArray objectAtIndex:i] forKey:@"FilterTypeCode"];
            [dic setValue:startTimeStr forKey:@"Value1"];
            [dic setValue:endTimeStr forKey:@"Value2"];
            [mDocumentLine1 addObject:dic];
            
        }
        
        [params setObject:mDocumentLine forKey:@"DataLineFileterParam"];
        [params setObject:mDocumentLine1 forKey:@"DataLineFileterParam2"];
        
        [HttpRequest requestData:@"StoreManager/GetOldMaterialList" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                  //  NSLog(@"shopcartlist===%@",severDataDict.dataDict);
                    _productTotalCount=[[severDataDict.dataDict objectForKey:@"TotalCount"] integerValue];
                    _oldGoldManageTotalCount.text=[NSString stringWithFormat:@"有%lu条记录",(unsigned long)_productTotalCount];
                    
                    if (_productTotalCount%6!=0) {
                        _productTotalPage=_productTotalCount/6+1;
                    }
                    else if (_productTotalCount%6==0)
                    {
                        _productTotalPage=_productTotalCount/6;
                    }
                   
                    NSMutableArray  *displayListArray=[severDataDict.dataDict objectForKey:@"DataLine"];
                    //   int total=0;
                    if ( displayListArray.count>0) {
                        for (int i=0; i< displayListArray.count; i++) {
                            [oldGoldNumArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocNum"]];
                           // [oldGoldQuatityArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"Number"]];
                            [oldGoldGuideNameArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"GuideName"]];
                            [oldGoldDateArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocDate"]];
                            [oldGoldStatusArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocStatus"]];
                            [oldGoldWeightArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"GramTotal"]];
                           // [oldGoldReasonArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"DocType"]];
                            [cutNumberArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"Number2"]];
                            [oldNumberArray addObject:[[displayListArray objectAtIndex:i] objectForKey:@"Number"]];
                        }
                    }
                    
                    [_oldGoldManageListTableView reloadData];
                   
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                        [Global loginViewController:self noteStr:requestResultStr];
                       // [Global loginViewController:self];
                    }

                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - _oldGoldManageListTableView.bounds.size.height, self.view.frame.size.width, _oldGoldManageListTableView.bounds.size.height)];
        view.delegate = self;
        [_oldGoldManageListTableView addSubview:view];
        _refreshHeaderView = view;
    }
    
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];

    // Do any additional setup after loading the view from its nib.
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    [oldGoldNumArray removeAllObjects];
    //[oldGoldQuatityArray removeAllObjects];
    [oldGoldGuideNameArray removeAllObjects];
    [oldGoldDateArray removeAllObjects];
    [oldGoldStatusArray removeAllObjects];
    [oldGoldWeightArray removeAllObjects];
   // [oldGoldReasonArray removeAllObjects];
    [cutNumberArray removeAllObjects];
    [oldNumberArray removeAllObjects];


    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    
}

- (void)doneLoadingTableViewData{
    
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:_oldGoldManageListTableView];
    
}


#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_oldGoldManageListTableView)
    {
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView==_oldGoldManageListTableView)
    {
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }
}


#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    
    [self reloadTableViewDataSource];
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
    
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    
    return _reloading; // should return if data source model is reloading
    
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    
    return [NSDate date]; // should return date data source was last changed
    
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //    NSMutableArray *codeArrays = [NSMutableArray arrayWithArray:[shopCartData objectForKey:@"PRODUCTCODE"]];
    //    return [codeArrays count];
    if (tableView ==_oldGoldManageListTableView) {
        return oldGoldNumArray.count;
    }
      return 1;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==_oldGoldManageListTableView)
        return 120.0f;
    return 55;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_oldGoldManageListTableView) {
        static NSString * identifier = @"Cell";
        OldGoldManageTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"OldGoldManageTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
             cell.delegate=self;
        }
         cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.submitBtn.tag=indexPath.row;
        if (oldGoldNumArray.count>0) {
            cell.numLabel.text=[NSString stringWithFormat:@"%@",[oldGoldNumArray objectAtIndex:indexPath.row]];
           // [self resizeLabel:cell.numLabel];
//            [Global resizeForLable:cell.numLabel WithText:cell.numLabel.text parentView:self.view];
//            CGRect frame=cell.statusLabel.frame;
//            frame.origin.x=cell.numLabel.frame.origin.x+cell.numLabel.frame.size.width+8;
//            cell.statusLabel.frame=frame;
        }
        if (oldGoldStatusArray.count>0) {
            
            NSString *statusStr=[oldGoldStatusArray objectAtIndex:indexPath.row];
            cell.statusLabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
            if ([statusStr isEqualToString:@"未上交"]) {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.submitBtn.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.submitBtn setUserInteractionEnabled:YES];
                [cell.submitBtn setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
              
            }
            else if ([statusStr isEqualToString:@"已上交"])
            {
                [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                cell.submitBtn.layer.borderColor=[[UIColor colorWithRed:245.0f/255.0f green:245.0f/255.0f blue:245.0f/255.0f alpha:1] CGColor];
                
                [cell.submitBtn setTitleColor:[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
                
                //[cell.confirmArrivalBtn setTintColor:];
                [cell.submitBtn setUserInteractionEnabled:NO];
            }
            else
            {
                 [cell.statusLabel setTextColor:[Global parseStatusColor:statusStr]];
                
                cell.submitBtn.layer.borderColor=[[UIColor colorWithRed:200.0f/255.0f green:200.0f/255.0f blue:200.0f/255.0f alpha:1] CGColor];
                [cell.submitBtn setUserInteractionEnabled:YES];
                [cell.submitBtn setTitleColor:[UIColor colorWithRed:60.0f/255.0f green:60.0f/255.0f blue:60.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
            }

            //[self resizeLabel:cell.statusLabel];
//             [Global resizeForLable:cell.statusLabel WithText:cell.statusLabel.text parentView:self.view];
//            CGRect frame=cell.reasonTagLabel.frame;
//            frame.origin.x=cell.statusLabel.frame.origin.x+cell.statusLabel.frame.size.width+15;
//            cell.reasonTagLabel.frame=frame;
//            CGRect frame1=cell.reasonLabel.frame;
//            frame1.origin.x=cell.reasonTagLabel.frame.origin.x+cell.reasonTagLabel.frame.size.width+2;
//            cell.reasonLabel.frame=frame1;
        }
//        if (oldGoldReasonArray.count>0) {
//            cell.reasonLabel.text=[oldGoldReasonArray objectAtIndex:indexPath.row];
//        }
        NSString *weightStr=@"";
        NSString *cutStr=@"";
        NSString *oldStr=@"";
        if (oldGoldWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02f",[[oldGoldWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (cutNumberArray.count>0) {
            cutStr=[NSString stringWithFormat:@"%ld",(long)[[cutNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        if (oldNumberArray.count>0) {
            oldStr=[NSString stringWithFormat:@"%ld",(long)[[oldNumberArray objectAtIndex:indexPath.row] integerValue]];
        }
        
        cell.detailLabel.text=[NSString stringWithFormat:@"共 剪金%@件、旧料%@件  总克重%@g",cutStr,oldStr,weightStr];

        if (oldGoldDateArray.count>0) {
            cell.dateLabel.text=[oldGoldDateArray objectAtIndex:indexPath.row];
        }
        if (oldGoldGuideNameArray.count>0) {
            NSString *guideNameStr=[oldGoldGuideNameArray objectAtIndex:indexPath.row];
            if (guideNameStr.length>0) {
                cell.guideNameLabel.text=guideNameStr;
            }
            else
            {
                cell.guideNameLabel.text=@"未填写";
            }
          //  [self resizeLabel:cell.guideNameLabel];
//          [Global resizeForLable:cell.guideNameLabel WithText:cell.guideNameLabel.text parentView:self.view];
//            CGRect frame=cell.dateTagLabel.frame;
//            frame.origin.x=cell.guideNameLabel.frame.origin.x+cell.guideNameLabel.frame.size.width+15;
//            cell.dateTagLabel.frame=frame;
//            
//            CGRect frame1=cell.dateLabel.frame;
//            frame1.origin.x=cell.dateTagLabel.frame.origin.x+cell.dateTagLabel.frame.size.width+3;
//            cell.dateLabel.frame=frame1;
            
            
        }
//        if (oldGoldQuatityArray.count>0) {
//            NSString *quatityStr=[NSString stringWithFormat:@"%d件",[[oldGoldQuatityArray objectAtIndex:indexPath.row] integerValue]];
//            cell.quatityLabel.text=quatityStr;//[shopCartMarketArray objectAtIndex:indexPath.row];
//            [self resizeLabel:cell.quatityLabel];
//            
//            CGRect frame=cell.weightTagLabel.frame;
//            frame.origin.x=cell.quatityLabel.frame.origin.x+cell.quatityLabel.frame.size.width+17;
//            cell.weightTagLabel.frame=frame;
//            
//            CGRect frame1=cell.weightLabel.frame;
//            frame1.origin.x=cell.weightTagLabel.frame.origin.x+cell.weightTagLabel.frame.size.width+3;
//            cell.weightLabel.frame=frame1;
//            
//        }
        
        
        if (indexPath.row == [oldGoldNumArray count] - 1)
        {
            if (_productPageIndex<=_productTotalPage) {
                //    NSLog(@"###LOADING???");
                [self loadProductNextPage:_productPageIndex];
            }
            
        }
        return cell;
    }
   
       return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView==_oldGoldManageListTableView) {
        oldCellTag=indexPath.row;
        docNumStr=[oldGoldNumArray objectAtIndex:indexPath.row];
        if (oldGoldDetailVC.view!=nil) {
            [oldGoldDetailVC.view removeFromSuperview];
            [oldGoldDetailVC removeFromParentViewController];
            
        }
        oldGoldDetailVC=[[OldGoldDetailViewController alloc] init];
        oldGoldDetailVC.delegate=self;
        oldGoldDetailVC.docNumStr=[oldGoldNumArray objectAtIndex:indexPath.row];
        
        oldGoldDetailVC.view.frame = CGRectMake(0,
                                              0,
                                              self.view.bounds.size.width,
                                              self.view.bounds.size.height);
        
        [self addChildViewController:oldGoldDetailVC];
        [self.view addSubview:oldGoldDetailVC.view];
    }
   
}
#pragma mark oldgolddetailDelegate
-(void)CancelOldBtnClick
{
    if (cancelOldVC.view!=nil) {
        
        [cancelOldVC removeFromParentViewController];
        [cancelOldVC.view removeFromSuperview];
        
    }
    cancelOldVC=[[CancelOldViewController alloc] init];
    
    cancelOldVC.DocNumStr=docNumStr;
   // cancelOldVC.DocTypeStr=@"Order";
    cancelOldVC.delegate=self;
    
    cancelOldVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOldVC];
    [self.view addSubview:cancelOldVC.view];

}
#pragma mark cancelOldDelegate
-(void)confirmCancelOldSuccess
{
    if (oldGoldDetailVC.view!=nil) {
        
        [oldGoldDetailVC removeFromParentViewController];
        [oldGoldDetailVC.view removeFromSuperview];
        
    }
    if (cancelOldVC.view!=nil) {
        [cancelOldVC removeFromParentViewController];
        [cancelOldVC.view removeFromSuperview];
    }

    [oldGoldNumArray removeAllObjects];
    //[oldGoldQuatityArray removeAllObjects];
    [oldGoldGuideNameArray removeAllObjects];
    [oldGoldDateArray removeAllObjects];
    [oldGoldStatusArray removeAllObjects];
    [oldGoldWeightArray removeAllObjects];
    // [oldGoldReasonArray removeAllObjects];
    [cutNumberArray removeAllObjects];
    [oldNumberArray removeAllObjects];
    
    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];
}
-(void)submitClick:(NSUInteger)tag
{
    if (oldGoldDetailVC.view!=nil) {
        [oldGoldDetailVC.view removeFromSuperview];
        [oldGoldDetailVC removeFromParentViewController];
        
    }
    if (submitVC.view!=nil) {
        [submitVC.view removeFromSuperview];
        [submitVC removeFromParentViewController];
        
    }
    submitVC=[[OldGoldDetailSubmitViewController alloc] init];
    submitVC.delegate=self;
    submitVC.docNumStr=[oldGoldNumArray objectAtIndex:tag];
    
    submitVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:submitVC];
    [self.view addSubview:submitVC.view];

}
-(void)submitOldClick
{
    if (submitVC.view!=nil) {
        [submitVC.view removeFromSuperview];
        [submitVC removeFromParentViewController];
        
    }
    [oldGoldNumArray removeAllObjects];
    //[oldGoldQuatityArray removeAllObjects];
    [oldGoldGuideNameArray removeAllObjects];
    [oldGoldDateArray removeAllObjects];
    [oldGoldStatusArray removeAllObjects];
    [oldGoldWeightArray removeAllObjects];
    // [oldGoldReasonArray removeAllObjects];
    [cutNumberArray removeAllObjects];
    [oldNumberArray removeAllObjects];
    
    
    _productPageIndex=0;
    [self loadProductNextPage:_productPageIndex];


}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField==_searchTextField) {
        [oldGoldNumArray removeAllObjects];
       // [oldGoldQuatityArray removeAllObjects];
        [oldGoldGuideNameArray removeAllObjects];
        [oldGoldDateArray removeAllObjects];
        [oldGoldStatusArray removeAllObjects];
        [oldGoldWeightArray removeAllObjects];
       // [oldGoldReasonArray removeAllObjects];
        [cutNumberArray removeAllObjects];
        [oldNumberArray removeAllObjects];

        
        _productPageIndex=0;
        [self loadProductNextPage:_productPageIndex];
        [_searchTextField resignFirstResponder];
    }
   
    
    return YES;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
